New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@homer0/ts-async-import

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@homer0/ts-async-import

Small utility to dynamically import ESM modules in CJS with TS

  • 1.1.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

☢️ TS Async Import

A wrapper to do dynamic imports in TypeScript contexts that target CommonJS.

🍿 Usage

⚠️ Don't use this package if you are targeting ES modules.

  • ⚙️ Examples
  • 🤘 Development

⚙️ Examples

import { tsAsyncImport } from '@homer0/ts-async-import';

// ...

const { default: nodeFetch } =
  await tsAsyncImport<typeof import('node-fetch')>('node-fetch');

That's it, the only difference between this and a regular import is that you need to specify the type of the module you are importing.

And, if for some reason, you want to specify the context path for the import, you can do it with the second parameter:

import { tsAsyncImport } from '@homer0/ts-async-import';

// ...

const { default: nodeFetch } = await tsAsyncImport<typeof import('node-fetch')>(
  'node-fetch',
  __dirname,
);

🤘 Development

As this project is part of the packages monorepo, some of the tooling, like lint-staged and husky, are installed on the root's package.json.

Tasks
TaskDescription
lintLints the package.
testRuns the unit tests.
types:checkValidates the TypeScript types.

Motivation

I didn't want to have to change my tsconfig.json just to prevent TS to transform the two imports I have into requires 🤬.

Keywords

FAQs

Package last updated on 25 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc